<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script src="./vue.js"></script>
  <!-- <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> -->
  <div id="app">
    Vue的模板
    <button v-on:mouseout="desc()">-</button>
    <span>{{totalCount}}</span>
    <button @mouseenter="desc2()">+</button>
    <!-- @=v-on: -->
  </div>
  <script>
    // 创建实例对象
    const app = new Vue({
      // 容器
      el: '#app',
      // 数据
      data: {
        totalCount: 1
      },
      methods: {
        desc() {
          if (app.totalCount === 1) {
            alert('不能再减了')
            return
          }
          app.totalCount--
        },
        desc2() {
          if (app.totalCount === 5) {
            alert('最多购买5件哦~')
            return
          }
          app.totalCount++
        }
      }
    })

  </script>
</body>

</html>